home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #2 / Amiga Plus CD - 1995 - No. 2.iso / internet / faq / englisch / vi-editor < prev    next >
Encoding:
Text File  |  1995-04-11  |  36.2 KB  |  851 lines

  1. Archive-name: editor-faq/vi/part1
  2. Posting-Frequency: 2nd and 17th of every month
  3. Last-modified: 1995/01/03
  4. Version: 1.0
  5.  
  6.                 vi editor FAQ 
  7.                                 -------------
  8.  
  9. 0.0 - Introduction -- How do I use this FAQ?
  10.  
  11.   This document is broken into multiple sections.  First, a general
  12. introduction and discussion of what vi is in sections 0 and 1.  Section
  13. 2 is a collection of "novice" questions, questions that someone without
  14. much experience with vi might ask.  These include the differences
  15. between command and insert mode, and continue ending with questions
  16. such as "How do I cut and paste?"  Then, section 3 is geared toward the
  17. intermediate vi user.  Starting with "How do I do a search and
  18. replace," and continuing onward from there, until it finally ends with
  19. a discussion of vi macros.  Also included is a vi quick reference.
  20. This should give a canonical list of vi commands.  Next, is a list of
  21. :set commands, all of which can be put into a .exrc file to customize
  22. your editing environment.
  23.   The quick reference was confirmed on a machine running SunOS with the
  24. UCB distribution of vi.  Each command should work under System V and
  25. UCB versions of vi other than the one shipped with SunOS, but I have
  26. not personally confirmed this.
  27.   Unless otherwise specified this document assumes that you are in
  28. command mode.
  29.   An attempt was made to retain much of the terminology used in the
  30. original vi documentation, wherever it did not seem to confuse more
  31. than necessary.
  32.  
  33. 0.1 - Index
  34.  
  35. First File:
  36.  
  37. 0.0 - Introduction -- How do I use this FAQ?
  38.   0.1 - Index
  39.   0.2 - Can I distribute this FAQ?
  40.   0.3 - What can you do to help out with this faq?
  41. 1.0 - What is vi?
  42.   1.1 - What is the big deal about vi?  Why does anyone use it?  More
  43.          importantly, why should *I* use it?
  44.   1.2 - Wow!  This sounds great!  Is there any reason not to use vi?
  45.   1.3 - What different operating systems is vi available for?
  46.   1.4 - Okay, you've convinced me.  I'm going to learn vi.  Where do I
  47.          start?
  48.   1.5 - What are some of the vi clones that are available?
  49. 2.0 - Learning vi.
  50.   2.1 - What games will help me learn vi?
  51.   2.2 - What is the difference between Command mode & Insert mode?
  52.   2.3 - Wait, my keyboard doesn't have a <Esc> key!  What should I do?
  53.   2.4 - What are all of those ~s?
  54.   2.6 - How do I quit without saving?
  55.   2.7 - How do I insert a file?
  56.   2.8 - How do I search for text?
  57.   2.9 - How do I search for a control sequence?
  58.   2.10 - How do I reformat text?
  59.   2.11 - How do I copy text?
  60.   2.12 - Ahhhh!!!  I just hit dG and lost my dissertation!  What can I
  61.           do?  (Or, I've just made a mistake, what should I do?)
  62.   2.13 - I've just written my dissertation and have been told that I 
  63.           need to have each section in a different file, what should 
  64.           I do?
  65.   2.14 - What's the deal with all of these : commands?
  66. 3.0 - How do you do a search and replace?
  67.   3.1 - How do I run a program from within vi?
  68.   3.2 - Ahhh!!  I was writing my dissertation, and the computer crashed!
  69.   3.3 - Any tips for making vi programmer friendly?
  70.   3.4 - Macros -- How do I write them?
  71.   3.5 - How do I make a function key a Macro?
  72.   3.6 - Is there anyway to abbreviate text?
  73.   3.7 - How do I spell check the current document?
  74.   3.8 - I've got a hardcopy terminal, can I still use vi?
  75.   3.9 - Oh, okay, is THAT what open mode is?  But I don't have a 
  76.          hardcopy terminal, and it still starts in open mode!
  77.  
  78. Second File:
  79.  
  80. 4.0 - What's online at the vi archives?
  81. 5.0 - Silly vi tricks, and silly macros
  82.   5.1 - Silly vi tricks
  83.   5.2 - Silly macros
  84. 6.0 - Alphabetical vi quick reference
  85.   6.1 - Command mode input options ( : commands)
  86.   6.2 - set options
  87. 7.0 - Setting up .exrc file
  88.   7.1 - Sample .exrc file
  89. 8.0 - Glossary of terms
  90. 9.0 - Bibliography of Books that cover vi
  91.  
  92. 0.2 - Can I distribute this FAQ?
  93.  
  94.   Yes, as long as you do not alter it in any fashion, or charge any
  95. money for it.
  96.  
  97. 0.3 - What can you do to help out with this faq?
  98.  
  99.   First, send me any errors that you may find.  Also, any suggestions
  100. that you might have are also appreciated.  Better yet, anything that
  101. you think is unclear.
  102.   Also, use vi!  Spread the word!  I'm sorry I can't list everyone who
  103. has contributed to this faq, as many, many people have given me advice
  104. and helped out, but I fear if I were to, the list of contributers would
  105. become as long as the document itself.
  106.  
  107. 1.0 - What is vi?
  108.  
  109.   vi is a Visual Editor (hence the name -- vi for VIsual).  What is a
  110. visual editor (as opposed to a non-visual one)?  Visual editors are
  111. ones that let you see the document that you are editing as you edit
  112. it.  This seems pretty common in most editors today, so the idea of a
  113. non-visual editor is a little strange.  Examples of non-visual editors
  114. are sed, ex, ed, and edlin (the last one being the editor shipped with
  115. DOS until relatively recently.)
  116.   vi was written by William Joy as part of the bsd distribution of
  117. Unix.  It was later used by AT&T, and has been standard Unix since.
  118.  
  119. 1.1 - What is the big deal about vi?  Why does anyone use it?  More
  120. importantly, why should *I* use it?
  121.  
  122.   vi is default visual editor under Unix, and is therefore shipped with
  123. all recent version of Unix.  (Recent being defined as post 1984 or
  124. so.)  This means that whenever you run across a machine that is running
  125. a Unix of some sort, you will know that you have a powerful editor at
  126. your finger tips.  Why else? vi is a powerful editor.  Also, once you
  127. know vi, you can edit files really quickly, as it is extremely
  128. economical with the keystrokes.  Due to its different modes for
  129. inserting and issuing commands, it is much faster than most non-mode
  130. based editors.  It is also a very small editor.  (The version on my
  131. machine is 200k) Also, it can do almost anything, as long as you know
  132. how to get it to do what you want.
  133.  
  134. 1.2 - Wow!  This sounds great!  Is there any reason not to use vi?
  135.  
  136.   Yes.  There is a very good reason.  It can be somewhat hard to learn,
  137. and until you do so, it will be slow and painful.  Once you learn it,
  138. it will be faster, but the process of learning it is slow.  I've been
  139. asked if vi was an easy editor to learn, whether it was intuitive or
  140. not.  My general response to this question is:  "Yes, some of us think
  141. so.  But most people think that we are crazy."
  142.  
  143. 1.3 - What different operating systems is vi available for?
  144.  
  145.  Unix.  That's it.  However, there are many, many clones of vi that are
  146. available for different operating systems.  I personally have used vi
  147. clones under:  Unix, Dos, OS/2, Mac System 7.  (See below for a list of
  148. specifics.)
  149.  
  150. 1.4 - Okay, you've convinced me.  I'm going to learn vi.  Where do I
  151. start?
  152.  
  153.   Well...  That's a tricky one.  There are many good books out there
  154. that cover vi; most books on Unix have at least one chapter devoted to
  155. it.  There are also many books devoted specifically to vi.  I don't
  156. have any preference, so your best bet might be to ask your local vi
  157. guru where they learned.  Also, play around.  Fire up vi with a
  158. non-important document (your dissertation is NOT a good document to
  159. learn vi with...) and play around.  I can't imagine anyone learning vi
  160. without playing around with it quite a bit.  Remember, if you get
  161. confused, just hit the Escape key a couple of times, and you'll be in
  162. command mode again.
  163.   I should mention at some point, and I guess here is as good a place
  164. as any, that people who think they might want to do Unix system
  165. administration, or any type of configuration of unix machines will
  166. probably also want to learn ed or ex, as some versions of Unix do not
  167. put vi in the root partition, and one might be stranded without it at
  168. some point.  Ed is a good choice.
  169.  
  170. 1.5 - What are some of the vi clones that are available?
  171.  
  172.   Just to list a few:  STvi (STevie), elvis, vile, vim, and nvi, xvi.
  173.  
  174. elvis is available for: Amiga, DOS, OS/2, Unix, VMS.  
  175. STevie is available for:  Atari ST, DOS, Unix.  
  176. nvi is the vi that will ship with BSD 4.4. 
  177. vim is available for: Amiga, DOS, Mac System 7, Unix.
  178.   Amiga, DOS, and the source are available at:
  179.     ftp.fu-berlin.de /misc/editors/vim 
  180. vile is available for: DOS, OS/2, Unix, VMS.  
  181. xvi is available for: DOS, Unix.
  182.  
  183.   There are some differences between the different vi clones.  Many
  184. offer improvements, but most still allow the commands that are listed
  185. in this document, but there may be some differences.  Refer to the
  186. documentation that comes with the clone for details.
  187.  
  188. 2.0 - Learning vi.
  189.  
  190.   These are some basic hints for the novice vi user.  First, keep a
  191. command summary with you at all times.  A quick reference guide/command
  192. summary is included later on.  Second, get a good book that covers vi.
  193. This document is not the best way to learn it (at least not yet.)  I'm
  194. not sure if this document should teach people to to use vi from
  195. scratch, as there are many good books on it already.  However, there
  196. are hints here.  As for choosing a book, the standard rules apply:
  197. look at it before buying it.  See if any of it makes sense to you.
  198. Make sure that it has exercises that you can practice with.  Compare it
  199. with other books -- after all, vi can be very confusing, and you want
  200. to make sure that it is the book that is confusing, and not just that
  201. you underestimated the difficulty of learning vi.
  202.   Also, seek out vilearn or vitutor, programs designed to teach you the
  203. basics of vi.
  204.  
  205. 2.1 - What games will help me learn vi?
  206.  
  207.   This may seem a bit silly, but there are many games on Unix systems
  208. that can help you learn to use vi.  These help particularly with the
  209. basics.  Although I don't know of any games that help with every vi
  210. command, I do know of a few that will help you learn to use hjkl to
  211. move the cursor around.  NetHack, a rouge-like game, is particularly
  212. good for this, as it is a large game and can be entertaining for quite
  213. some time.  Not to make the other games sound worse, but some other
  214. ones are:  rouge, moria, omega, worm, and snake.
  215.  
  216. 2.2 - What is the difference between Command mode & Insert mode?
  217.  
  218.   Often sited as one of the main problems with vi, and equally often
  219. sited as being one of its best strengths, vi differentiates between a
  220. "Command mode" and an "Insert mode."  Understanding this difference is
  221. VITAL to learning vi.  When one starts vi it starts in command mode.
  222. In this mode, one can move around the file, and issue commands to
  223. change certain areas of the text, cut, copy and paste sections of the
  224. text and do much more.  Insert mode is where one can actually insert
  225. text.  In other words, command mode is used to move around the
  226. document, and insert mode is used to type text into the document.
  227.   Commands such as:  a, i, c, C, O, o and others will switch one from
  228. command mode to insert mode.
  229.   <Esc> or ^C will take one out of insert mode and return one to
  230. command mode.
  231.   Get used to this distinction.  It is one of the things that makes vi
  232. different from most other editors.  It also allows one to do a lot of
  233. things without taking one's hands from the standard keyboard position.
  234.  
  235. 2.3 - Wait, my keyboard doesn't have a <Esc> key!  What should I do?
  236.  
  237.   Try hitting ^[ instead.  If your keyboard has a <Meta> key, try
  238. that.  If neither of these work, try ^3.
  239.  
  240. 2.4 - What are all of those ~s?
  241.  
  242.   They're just there to let you know where the bottom of your file is,
  243. they are not actually in your document, and you do not need to worry
  244. about them.
  245.  
  246. 2.5 - I can't get used to using hjkl, do you have any suggestions?
  247.  
  248.   First, if your terminal is set properly, you should be able to use
  249. the arrow keys.  However, if you think that you will be using vi a lot,
  250. then it makes sense to learn hjkl, as they are faster to type.
  251.  
  252. 2.6 - How do I quit without saving?
  253.  
  254.   :q! will do it.  If vi appears to have frozen, make sure that you
  255. haven't hit ^S by mistake.  In order to undo a ^S, hit ^Q.
  256.  
  257. 2.7 - How do I insert a file?
  258.  
  259.   :r <filename>
  260.  
  261.   For example, to insert the file /etc/motd, type:  :r /etc/motd
  262.  
  263.   This will insert the file at the current location in the file you are
  264. working on.  If you specify a number before the r, it will insert it at
  265. that location in the file.
  266.  
  267. 2.8 - How do I search for text?
  268.  
  269.   /<text> will search forward.  ?<text> will search backwards.  ?? or
  270. // will repeat the last search.  It is worth noting that these are
  271. pretty much standard in Unix.  In addition, in vi, n will find the next
  272. occurrence.  N will repeat the last search, reversing the direction.
  273. Regular Expressions may be used within searches.
  274.  
  275. 2.9 - How do I search for a control sequence?
  276.  
  277.   /^V^<seq>
  278.  
  279.  ^V will tell vi to take the next character literally, and not to take
  280. it as a command.
  281.  
  282. 2.10 - How do I reformat text?
  283.  
  284.   If your computer has the program fmt on it, all you need to do is
  285. type !}fmt from insert mode.  This will rejustify the text from the
  286. current location until the end of the paragraph.  If your machine does
  287. not have fmt, you need to find a similar program.  (I gather there are
  288. many such programs available from the public domain, but I do not know
  289. much about them.)
  290.  
  291. 2.11 - How do I copy text?
  292.  
  293.   Okay, this might be a bit complicated.  Take from this section what
  294. you can, and reread it a few times.  Also, experiment.
  295.   "<letter>yy will copy one line of text into register <letter>.  (A
  296. register is vi-lingo for a place to store data that was cut or copied.)
  297. <letter> must be between a and z.  "<letter>dd will delete one line and
  298. place it in register <letter>.  You may use a number before the yy or
  299. dd to specify the number of lines.  Using an uppercase <letter> will
  300. append the text into the register leaving what was there before.
  301. "<letter>p will put the text after the cursor.  "<letter>P will put it
  302. before the cursor.  If the register contains the beginning or end of a
  303. line, the line will be placed on another line as appropriate.  Y may be
  304. used as a short cut for yy.  In addition, y$, yH, yM, etc. are valid,
  305. as are the equivalent d commands.  For quick cuts and pastes, no
  306. register need be specified.  In this case, no appending is allowed, and
  307. the register will be removed if another delete command is given.
  308. (Including x).
  309.   For example, to move the previous paragraph, one would go to the top
  310. of the paragraph, type "a13dd, move to the position in which one wishes
  311. to put the paragraph, and then type "ap to put it below the current
  312. line.
  313.   Now, presumably you want to be able to cut and paste into areas that
  314. are not just the end of the line.  In order to do this, use m<letter>
  315. to mark an area.  This letter may be the same as a cut/copy register,
  316. they are stored in different area of memory.  Then, type
  317. "<register>`<letter>[yy or dd].  Where <register> is the register to
  318. put the text into, <letter> is the letter used to make, and yy or dd as
  319. appropriate.
  320.  
  321. 2.12 - Ahhhh!!!  I just hit dG and lost my dissertation!  What can I
  322. do?  (Or, I've just made a mistake, what should I do?)
  323.  
  324.   u will undo the last command.  U will undo changes to the current
  325. line.  (Granted, a one line dissertation would not be much.) :e! will
  326. reload the current document without saving any changes.  In addition,
  327. deleted text gets stored in the registers numbered from 1 to 9.  "<n>p
  328. will put the last nth deletion.  You can quickly search the registers
  329. by trying one, hitting u, and trying the next.  (In order to expedite
  330. this, vi uses . slightly differently than normal.  Instead of repeating
  331. the last command, it will try the next register, so all you need to do
  332. is: "1p u . u ., etc. until you undo the delete you want to undo.)
  333.  
  334.  
  335. 2.13 - I've just written my dissertation and have been told that I need
  336. to have each section in a different file, what should I do?
  337.  
  338.  :[m],[n]w <filename> will save between lines m and n to <filename>.
  339. This line numbering method works for almost every : command.  If you
  340. use :[m],[n]w >> <filename> it will append it to the file.
  341.  
  342. 2.14 - What's the deal with all of these : commands?
  343.  
  344.   The commands that follow a : are commands from the ex editor.  These
  345. allow a lot of flexibility and power.  For example, there are many
  346. different ways to search and replace, all of with have some
  347. similarities (in fact, they are in some ways the same...)
  348.  
  349. 3.0 - How do you do a search and replace?
  350.  
  351.   Well, there are a few methods.  The simplest is:
  352.     :s/old/new/g But, this only does it on the current line...  So:
  353.     :%s/old/new/g In general,
  354.     :[range]s/old/new/[cg] Where [range] is any line range, including
  355. numbers, $ (end of file), . (current location), % (current file), or
  356. just two numbers with a dash between them.  (Or even: .,+5 to mean the
  357. next five lines).  [cgi] is either c, g, i, or nothing.  c tells vi to
  358. prompt you before the changes, g to change all of the occurrences on a
  359. line.  i tells vi to be case insensitive on the search.  No character
  360. after the last slash will only change the first occurrence on the line.
  361.   My favorite method is:
  362.     :g/foobar/s/bar/baz/g This searches for foobar, and changes it to
  363. foobaz.  It will leave jailbars alone, which the other method will
  364. not.  This is my favorite method, but is harder to remember.
  365.   Of course you can also use regular expression search patterns, and a
  366. few other commands in the replacement part of the text.  If you use
  367. \( and \) in the pattern to escape a sequence, you can do lots of nifty
  368. things.
  369.   For example:
  370.     :g/\(foo\)\(bar\)/s/\2/\1baz/g will change foobar for foobaz.
  371.   Special sequences allowed are:
  372.     &        everything which was matched by the search 
  373.     \[1-9]   The contents of the 1st-9th \(\) pair 
  374.     \u       The next character will be made uppercase 
  375.     \U       The characters until \e or \E will be made uppercase 
  376.     \l       The next character will be made lowercase
  377.     \L       The characters until \e or \E will be made lowercase
  378.     \[eE]    end the selection for making upper or lowercase
  379.  
  380. 3.1 - How do I run a program from within vi?
  381.  
  382.   :!cmd will run the program cmd.  :sh will run an interactive shell.
  383. Within this shell, you may, if you want, run vi again.  This is
  384. particularly useful when you are editing makefiles and config files for
  385. programs in an attempt to get a program to compile.  The advantage over
  386. :e is that you do not need to save the file, and it will be in its old
  387. place when you exit the shell.  (I advise saving the file anyway...)
  388.  
  389. 3.2 - Ahhh!!  I was writing my dissertation, and the computer crashed!
  390.  
  391.   Well, you should get mail about this, but you should be able to
  392. recover the file by typing vi -r <filename> where <filename> is the
  393. name of the file that you were editing at the time of the crash.  vi -r
  394. will give you a list of files that can be recovered.
  395.  
  396. 3.3 - Any tips for making vi programmer friendly?
  397.  
  398.   :set ai will make it auto-indent for you.  
  399.   :set sw=# where # is a number will set the shiftwidth (tabwidth).  
  400. You can then use <<, >> to shift a line left or right.  Plus, you 
  401. can use <% to shift a {, ( or [ set left or right (with >%).  
  402. You must be on top of the specific {, }, (, ), [ or ] of the pair 
  403. to shift them.  
  404.   :set sm will show the matching {, ( or [ when you type the closing
  405. one.  
  406.   :set lisp will make some changes that are useful for lisp
  407. programming.  () will move back and forth over s-expressions, and {}
  408. will move without stopping at atoms.
  409.  
  410. 3.4 - Macros -- How do I write them?
  411.  
  412.   :map <lhs> <rhs> where <lhs> is up to ten characters and <rhs> is up
  413. to 100.  This will make it so that whenever you type <lhs> it will
  414. replace it with <rhs>.  All macros should start in command mode, but
  415. may end in any mode you desire.  Remember to use ^V before any control
  416. characters that you may use.
  417.   :unmap <lhs> will remove the macro.  :map! <lhs> <rhs> will make
  418. <lhs> insert <rhs> into the text of the document.
  419.  
  420. 3.5 - How do I make a function key a Macro?
  421.  
  422.   If <lhs> is #n where n is 0-9, it will be mapped to the appropriate
  423. function key.
  424.  
  425. 3.6 - Is there anyway to abbreviate text?
  426.  
  427.   Yep, of course.  This is vi, it can do anything.  :ab email
  428. ellidz@midway.uchicago.edu will make it so that whenever you type
  429. email as a specific word, it will extend it to the entire
  430. unabbreviated word.  :una email will unabbreviate it.
  431.  
  432. 3.7 - How do I spell check the current document?
  433.  
  434.   Here is a macro to do it.  These should be put in your .exrc file.
  435. (More on .exrc files later on.) It is a pretty simple macro, it just
  436. calls ispell on the current file.  Of course, to use this you need
  437. ispell on your system.  To use it, just hit V with vi.  (V is not used
  438. by vi, so it makes a good key.)
  439.  
  440.   map V :w^M:!ispell % ^M:e!^M^M
  441.  
  442. The second ^M makes it so that one does not need to hit return after it
  443. is done checking the spelling.
  444.  
  445. 3.8 - I've got a hardcopy terminal, can I still use vi?
  446.  
  447.   Okay, okay, so I don't expect anyone to actually ask this...  But, I
  448. thought it was bizarre enough to throw in anyway.  (And, it actually
  449. answers a very common question...)
  450.   vi will start up in a specific mode, called "open mode" in this
  451. situation.  Things work more or less the same.  Deleted characters will
  452. appear on your print out at \'s.  vi will act as if the size of the
  453. window is only one line.  ^r will retype the current line.  z redraws
  454. the window around the current line.
  455.  
  456. 3.9 - Oh, okay, is THAT what open mode is?  But I don't have a
  457. hardcopy terminal, and it still starts in open mode!
  458.  
  459.   Well, what is happening here is that vi doesn't know what type of
  460. terminal you have.  It decides that in this situation the best thing to
  461. do is to assume that you have the worst terminal possible.  This might
  462. not seem useful, as not very many people need open mode, but it also is
  463. the mode that needs to know the least information about your terminal.
  464.   Now, how to deal with it.  It is possible to change it for the
  465. specific session, but in general, this is not useful.  If you know
  466. your terminal type, you can set it from the Unix prompt (setenv TERM
  467. <termtype> under csh and it's variants, and:  TERM=<termtype> ; export
  468. TERM under sh and its variants.).
  469.   Better yet would to be to edit your .profile or .chsrc to include
  470. this so it is automatically done for you when you login.  (Of course,
  471. you need to either know ed or be able to set it at the unix prompt
  472. before you'll be able to edit the file...)
  473.   If you do not know your terminal type, try vt100.  Most modern
  474. terminals and terminal emulators can emulate vt100.  If this does not
  475. work, find someone to help you.
  476. Archive-name: editor-faq/vi/part2
  477. Posting-Frequency: 2nd and 17th of every month
  478. Last-modified: 1995/01/03
  479. Version: 1.0
  480.  
  481. 4.0 - What's online at the vi archives?
  482.  
  483.   There is a FAQ posted frequently which gives a list of all the files
  484. that are online at the vi archive.  It also gives a list of addresses
  485. which mirror the vi archive.  The main address is alf.uib.no, but it is
  486. archived at many, many sites.  The vi-archive faq lists all of them.
  487. Please check that faq before ftping to it, as there is almost defiantly
  488. a closer and therefore faster site to you that the one in Norway.
  489.   A mirror site is available at:  cs.uwp.edu /pub/vi, and another at
  490. monu6.cc.monash.edu.au /pub/Vi.
  491.   The site has many, many files on vi, including a few clones.  It also
  492. has the UCB distribution of vi, and lots of useful macros.  Check it
  493. out.
  494.  
  495. 5.0 - Silly vi tricks, and silly macros
  496.  
  497.   This section is for silly vi tricks, and silly macros.  Actually, any
  498. interesting vi tricks and macros are acceptable, as long as they are
  499. not too lengthy.  I will add any that are suggested to me that I think
  500. are reasonable.
  501.  
  502. 5.1 - Silly vi tricks
  503.  
  504.   xp     This will delete the character under the cursor, and put it
  505. afterwards.  In other words, it swaps the location of two characters.
  506.  
  507. 5.2 - Silly macros
  508.  
  509.   None at the moment, suggest some.
  510.  
  511. 6.0 - Alphabetical vi quick reference
  512.  
  513.   ... means that something needs to be specified before or after the
  514.   command, as appropriate.  This is normally a cursor movement 
  515. keys (h,j,k,l,w,b, etc.) or a line number.
  516.  
  517.   #  (where # is a number) following command n times...  
  518.   :  go to ex-mode 
  519.   )  next sentence 
  520.   (  previous sentence 
  521.   }  next paragraph 
  522.   {  previous paragraph 
  523.  ]]  next section 
  524.  [[  previous section
  525.   0  beginning of line 
  526.   $  end of line 
  527.   ^  first non-whitespace character
  528.   +  first character of next line 
  529.   -  first character of previous line 
  530. (spacebar) next character 
  531. (return) next line 
  532.   /  search forward 
  533.   ? search backward 
  534.   %  find match of current parenthesis, brace, or bracket 
  535.   ,  reverse direction of last f, F, t, or T 
  536.   ;  repeat last f, F, t, or T
  537.   .  repeat last command
  538.   `  goto mark 
  539.   '  goto beginning of line with mark 
  540.  ``  return to previous mark or location before a search 
  541.  ''  go to start of line of previous mark or location before search
  542.   ~  switch case of current character 
  543.   "  store in register 
  544.  !!  repeat last shell command
  545.   !  send next to command, replace output (eg  !}fmt passes the current
  546.        paragraph to the command fmt, and replaces the output with
  547.        whatever fmt returns.) 
  548.  >>  shift paragraph one shiftwidth to the right 
  549.  <<  shift paragraph one shiftwidth to the left 
  550.  >%  shift until matching (, [, or { to the right 
  551.  <%  shift until matching (, [, or { to the left
  552.   a  append after the current location 
  553.   A  append at the end of the line
  554.  ^a  unused
  555.   b  beginning of previous word 
  556.   B  beginning of previous word, ignore punctuation 
  557.  ^b  scroll back one screen
  558.   c  change until...  
  559.   C  change to end of line 
  560.  ^c  ends insert mode, unused in command mode
  561.   d  delete until...  
  562.   D  delete to end of line 
  563.  ^d  scroll down half a window, moves to previous shiftwidth in insert
  564.        mode
  565.   e  end of word 
  566.   E  end of word, ignore punctuation 
  567.  ^e  scroll screen down one line
  568.   f  find...  
  569.   F  find backward...  
  570.  ^f  scroll forward one screen
  571.   g  unused 
  572.   G  ...Goto  [defaults to end of file] 
  573.  ^g  show status line
  574.   h  left 
  575.   H  first line on screen 
  576.  ^h  backspace in insert mode, left in command mode
  577.   i  insert before current location 
  578.   I  insert before first non-whitespace character on line 
  579.  ^i  tab in insert, unused in command
  580.   j  down 
  581.   J  join next line with current line 
  582.  ^j  down in command, create newline in insert
  583.   k  up 
  584.   K  unused 
  585.  ^k  unused
  586.   l  right 
  587.   L  last line on screen 
  588.  ^l  redraw screen
  589.   m  mark position into register 
  590.   M  middle of screen 
  591.  ^m  carriage return
  592.   n  repeat last search 
  593.   N  repeat last search, reverse direction 
  594.  ^n down in command
  595.   o  open line below current 
  596.   O  open line above current 
  597.  ^o  unused
  598.   p  put below current line 
  599.   P  put above current line 
  600.  ^p  up in command
  601.   q  unused 
  602.   Q  quit and run ex 
  603.  ^q  unused
  604.   r  replace current character 
  605.   R  replace characters until insert mode is left 
  606.  ^r  redraw screen in command mode
  607.   s  substitute 
  608.   S  substitute entire line 
  609.  ^s  unused
  610.   t  to...  
  611.   T  backward to...  
  612.  ^t  moves to next shiftwidth.
  613.   u  undo last change 
  614.   U  undo changes to current line 
  615.  ^u  scroll up half a window
  616.   v  unused 
  617.   V  unused 
  618.  ^v  unused
  619.   w  beginning of next word 
  620.   W  beginning of next word, ignore punctuation 
  621.  ^w  unused in command, in insert move back to beginning of previous
  622.        word
  623.   x  delete current character 
  624.   X  delete previous character 
  625.  ^x  unused
  626.   y  yank...  
  627.   Y  yank current line 
  628.  ^y  scroll screen up one line
  629.   z  reposition screen around line (Return to top of screen, . to 
  630.        middle, - to bottom) 
  631.  ZZ  write and quit 
  632.  ^z  unused
  633.  
  634. 6.1 - Command mode input options ( : commands)
  635.  
  636.   (Note: this is not a canonical list, just some of the more important
  637. ones.)
  638.  
  639.  :r <file>       read <file> into current text 
  640.  :r !<command>   read output from command <command> into current text 
  641.  :nr <file>      read in at line number 
  642.  :!<file>        run command, return 
  643.  :sh             goto shell 
  644.  :so <file>      read and execute commands from <file>
  645.  :x              write and quit 
  646.  :wq             write and quit 
  647.  :l1,l2w <file>  write between lines l1 and l2 to <file>.  If <file> 
  648.                    is not specified, assume current.  If l1,l2 not 
  649.                    specified, assume entire file (making it :w)
  650.  :w >> <file>    append to <file>.  May use line numbers
  651.  :w!             overwrite current file 
  652.  :q              quit
  653.  :q!             quit, forget changes 
  654.  :e <file>       edit <file> without leaving vi 
  655.  :e!             forget changes since last write
  656.  :n              edit next file 
  657.  :e +n <file>    edit <file> at line n, if no end, assume end of file 
  658.  :n <files>      specify <files> as new list of files to edit 
  659.  :e#             edit alternate file (if :e <file> is used, alternate is
  660.            the original file)
  661.  :args           show files to be edited 
  662.  :rew            rewind life of files to top 
  663.  :map m n        create a macro (make m do n) 
  664.  :map! m n       create an insert mode macro (make m do n) 
  665.  :unmap m        destroy macro m 
  666.  :unmap! m       destroy insert mode macro m 
  667.  :ab <1> <2>     abbreviate - replace <1> with <2> whenever typed as 
  668.                    a word
  669.  :unab <1>       unabbreviate <1> 
  670.  :set <option>   set <option>...
  671.  
  672. 6.2 - set options
  673.  
  674. The abbreviations in parenthesis may be used.  Syntax:
  675.  
  676.   :set <option> <param>   (If <param> is expected) 
  677.   Multiple options may be specified on one line.  
  678.   :set <option>? displays the value of the <option> 
  679.   :set all displays the value of all the options.  
  680. For options without a value, set no<option> turns it off.
  681.  
  682. Option:             Default:           What it does:
  683.  
  684. autoindent (ai)     noai               Makes new lines automatically
  685.                                          indent to the position as the 
  686.                                          line above or below
  687. autoprint (ap)      ap                 Display changes after each 
  688.                                          command 
  689. autowrite (aw)      noaw               Automatically save file 
  690.                                          before :n, :!  
  691. beautify (bf)       nobf               Ignore all control characters
  692.                                          during input (except tab, 
  693.                                          newline, formfeed)
  694. directory= (dir=)   /tmp               Name of the directory to store 
  695.                                          buffer 
  696. edcompatible        noedcompatible     Use ed-like features on 
  697.                                          substitute 
  698. errorbells (eb)     errorbells         Sound bell on error
  699. exrc (ex)           noexrc             Allow .exrc files outside home 
  700.                                          dir 
  701. hardtabs= (ht=)     8                  Set boundary for hardware tabs 
  702. ignore case (ic)    noic               Ignore case in regex expressions 
  703. lisp                nolisp             Turn on lisp mode
  704. list                nolist             Display all tabs, end of lines
  705. magic               magic              Enable more regex expressions
  706. mesg                mesg               Allows mesgs to be sent to 
  707.                                          terminal 
  708. number (nu)         nonumber           Displays line numbers in file 
  709. open                open               Allows open and visual
  710. optimize (opt)      optimize           Optimizes throughput of text by 
  711.                                          not sending carriage returns 
  712.                                          when printing text
  713. paragraphs= (para=) IPLPPPQPPLIbp      Sets the delimiters for { & }
  714. prompt              prompt             Command mode input gives : prompt 
  715. readonly (ro)       noro               Cannot write unless ! is given  
  716. redraw              noredraw           Redraw screen when edits are made 
  717. remap               remap              Allows macros that point to other
  718.                      macros
  719. report=             5                  Report changes if they effect > x
  720.                      lines
  721. scroll              1/2 window         Amount of screen to scroll when
  722.                      scroll down is received in
  723.                      command mode.  Also, number of
  724.                      lines printer by z.  (z prints
  725.                      2*scroll)
  726. sections=           SHNHH HU           Defines end of section for [[ 
  727.                                          and ]] 
  728. shell= (sh=)        /bin/sh            Default shell.  Uses SHELL
  729.                      environment, if set
  730. shiftwidth= (sw=)   8                  Characters to shift when using
  731.                      shift commands
  732. showmatch (sm)      nosm               Show matching {, }, (, ), [, or ] 
  733. showmode            noshowmode         Shows which mode you are in.
  734. slowopen (slow)                        Do not update display 
  735.                                          immediately after insert
  736. tabstop= (ts=)      8                  Sets tabstop length 
  737. taglength= (tl=)    0                  Number of characters significant
  738.                                          for tags (0 means all 
  739.                                          characters)
  740. tags=               tag, /usr/lib/tags Define pathname of files 
  741.                                          containing tags.
  742. term=                                  Set the terminal type
  743. terse               noterse            Display shorter error messages
  744. timeout (to)        timeout            Keyboard maps timeout after one 
  745.                                          second 
  746. ttytype=                               Set the terminal type
  747. warn                warn               Display "No write since last 
  748.                                          change" messages
  749. window= (w=)                           Number of lines in window in visual
  750.                      mode
  751. wrapmargin= (wm=)   0                  Set the right margin.  Greater 
  752.                                          than 0 will word wrap n spaces
  753.                                          from the edge of the screen
  754. wrapscan (ws)       ws                 Searches wrap around end of file
  755. writeany (wa)       nowa               Allow saving to any file
  756.  
  757. 7.0 - Setting up .exrc file
  758.  
  759.   Any commands that can be used in command input mode ( : commands),
  760. may be used in a .exrc, which will load automatically whenever you
  761. start vi.  In addition, the source command (so), abbreviations (ab),
  762. and macros may be used.  There may not be any blank lines in your
  763. .exrc.  A " in the first column may be used to tell vi that what
  764. follows is a comment.
  765.  
  766. 7.1 - Sample .exrc file
  767.  
  768.   This .exrc file is a real one.  Mine.  Because of that, it doesn't
  769. set as many options as one might wish it did to get a good idea of what
  770. may be used.  However, it should get the basic idea down, and it is
  771. quite straightforward.
  772.  
  773. set wm=3 
  774. set sm 
  775. " abbreviations for my email address.
  776. ab zidllem E. Larry Lidz - ellidz@midway 
  777. ab zidlleu E.  Larry Lidz - ellidz@midway.uchicago.edu 
  778. map V :w^M:!ispell -x %^M:e!^M^M
  779.  
  780. First, note that you do not need to specify the :, it is assumed.
  781.  
  782.   The first line, set wm=3 sets the warpmargin to be three characters
  783. from the right of the screen.  This gives me a nice wordwrap.
  784.  
  785.   The second line sets showmatch so that whenever I type a }, ) or ],
  786. it shows the matching brace, parenthesis, or bracket.  This is useful
  787. for the programming I do.
  788.  
  789.   The third line sets an abbreviation so that whenever I type zidllem
  790. as a word by itself it expands to my name and email address.  The
  791. fourth is similar except that it gives the whole address, not just the
  792. local one.
  793.  
  794.   The fifth line sets V to automatically run ispell on the current
  795. document passing it the -x parameter so that it doesn't save any
  796. backups.  (I don't like filling my directories with useless backups.)
  797.  
  798. 8.0 - Glossary of terms
  799.  
  800.   This glossary will be updated as people suggest terms that they do
  801. not understand.  Please let me know if you have any suggestions.
  802.  
  803.   command mode 
  804.     Command mode is the mode within vi where the user gives commands to
  805. vi.  (Including cursor movement commands, editing commands, etc.)
  806.  
  807.   ed 
  808.     A non-visual editor under unix.
  809.  
  810.  <Esc> 
  811.     The escape key.  A key on a keyboard normally marked by escape.
  812. Sometimes ^[ will work in its place.  If there is no escape key,
  813. sometimes the Meta key will work.
  814.  
  815.   ex 
  816.     An editor under unix, all commands preceded with : are passed to
  817. it.
  818.  
  819.   insert mode 
  820.     Insert mode is the mode within vi where text is inserted into the
  821. document.
  822.  
  823.   macro 
  824.     A macro is a shortcut key combination.  For example, a macro allows
  825. one to hit one letter and have it execute a few different commands.
  826.  
  827.   open mode 
  828.     Open mode is the mode that vi will start in if it cannot determine
  829. your terminal type, or if it believes you have a hardware or glass-tube
  830. terminal.
  831.  
  832.   regular expressions (RegEx) 
  833.     Regular expressions, commonly known as "RegEx" are a set of key
  834. combinations that are meant to allow people to have a large variety of
  835. control over what they are searching for.  RegEx is used a lot under
  836. Unix, and is common between many programs.
  837.  
  838.   sed 
  839.     Stream-line editor.  An editor that has no interface.  All commands
  840. are given from the command line.
  841.  
  842.   vi 
  843.     The editor to which this FAQ is dedicated.
  844.  
  845. 9.0 - Bibliography of Books that cover vi
  846.  
  847.   Please make suggestions as to what books are most useful for learning
  848. vi.  I will add books to this section as people suggest them to me.
  849.  
  850. (C)opyright, E. Larry Lidz, 1994, 1995.  All Rights Reserved.
  851.